package com.freecat.xmqgct.utils;

import android.support.v7.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.github.ybq.android.spinkit.style.Circle;
import com.freecat.xmqgct.R;

/**
 * 作者：ChenPeng
 * 时间：2019/1/3
 * 注释：
 */
public class CustomDialog {
    public static AlertDialog progress(Context context) {
        View view = LayoutInflater.from(context).inflate(R.layout.dialog_progress_bar, null);
        ProgressBar progressBar = view.findViewById(R.id.progressbar);
        progressBar.setIndeterminateDrawable(new Circle());

        AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.MyProgressStyle).setCancelable(false).setView(view).create();
        alertDialog.getWindow().setDimAmount(0);
        return alertDialog;
    }

    public static AlertDialog notice(Context context, String title, String msg, AlertDialogCallBack callBack) {
        View view = LayoutInflater.from(context).inflate(R.layout.alert_dialog_layout, null);
        TextView tvTitle = view.findViewById(R.id.tv_title);
        TextView tvContent = view.findViewById(R.id.tv_content);
        Button btnConfirm = view.findViewById(R.id.btn_confirm);
        Button btnCancel = view.findViewById(R.id.btn_cancel);
        tvTitle.setText(title);
        tvContent.setText(msg);
        AlertDialog alertDialog = new AlertDialog.Builder(context,R.style.MyProgressStyle).setView(view).create();
        btnConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.onConfirm();
                alertDialog.dismiss();
            }
        });
        btnCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                callBack.onCancel();
                alertDialog.dismiss();
            }
        });
        return alertDialog;
    }
}
